package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Api("远程调用")
@RestController
@RequestMapping("/api/product")
public class ProductApiController {

    @Autowired
    private ManageService manageService;

    @ApiOperation("查询一二三级分类")
    @GetMapping("/inner/getCategoryViewByCategory3Id/{category3Id}")//inner 表示内部资源，只允许微服务之间远程调用，不支持浏览器调用
    public BaseCategoryView getBaseCategoryView(@PathVariable Long category3Id){
        return manageService.getBaseCategoryView(category3Id);
    }

    @ApiOperation("查询Sku中的信息及图片")
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){
        return manageService.getSkuInfo(skuId);
    }

    @ApiOperation("获取商品价格")
    @GetMapping("/inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId){
        return manageService.getSkuPrice(skuId);
    }



    @ApiOperation("查询spu中总销售属性及属性值，默认一个商品")
    @GetMapping("/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable Long skuId,@PathVariable Long spuId){
       return manageService.getSpuSaleAttrListCheckBySku(skuId,spuId);

    }


    @ApiOperation("查询页面上的组合与skuId之间的关系")//{1|2|3,1|3|4}json格式的字符串
    @GetMapping("/inner/getSkuValueIdsMap/{spuId}")
    public Map<String,String> getSkuValueIdsMap(@PathVariable("spuId") Long spuId){
        return manageService.getSkuValueIdsMap(spuId);
    }

    @ApiOperation(value = "查询所有的首页对象")
    @GetMapping("/getBaseCategoryViewList")
    public List<BaseCategoryView> getBaseCategoryViewList(){
        return manageService.getBaseCategoryViewList();
    }


    @ApiOperation("根据tmId查询一个品牌")
    @GetMapping("/getBaseTrademark/{tmId}")
    public BaseTrademark getBaseTrademark(@PathVariable Long tmId){
        return manageService.getBaseTrademark(tmId);
    }

    @ApiOperation("查询总和表")
    @GetMapping("/getSkuAttrValue/{skuId}")
    public List<SkuAttrValue> getSkuAttrValue(@PathVariable Long skuId){
        return manageService.getSkuAttrValue(skuId);
    }
}
